package com.hxtec.polaris.controller;

import com.hxtec.polaris.commons.aop.Log;
import com.hxtec.polaris.entity.ShopCarouse;
import com.hxtec.polaris.service.CarouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @Describtion 轮播图相关
 * @Author yonyong
 * @Date 2019/11/14 10:48
 * @Version 1.0.0
 **/
@RestController
@RequestMapping(value = "carouse",produces = "application/json;charset=utf-8")
@CrossOrigin
@Api(value = "/carouse", tags = "轮播图")
public class CarouseController {

    @Autowired
    private CarouseService carouseService;

    /**
     * 首页页面 获取轮播图数据
     * @return
     */
    @ApiOperation("获取轮播图列表")
    @GetMapping("getAll")
    public Object getAll(){
        return carouseService.getAll();
    }

    /**
     * 分类相关 删除分类节点
     * @return
     */
    @ApiOperation("删除轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids[]", value = "删除的id集合", required = false,allowMultiple=true, dataType = "String")
    })
    @DeleteMapping("delete")
    @Log(value = "删除首页轮播图",comment = "管理员删除首页轮播图")
    public Object deleteCarouse(int[] ids){
        return carouseService.deleteCarouse(ids);
    }

    @PostMapping("add")
    @Log(value = "添加首页轮播图",comment = "管理员添加首页轮播图")
    public Object addCarouse(ShopCarouse shopCarouse){
        return carouseService.addCarouse(shopCarouse);
    }

    @PutMapping("update")
    @Log(value = "更新首页轮播图",comment = "管理员更新首页轮播图")
    public Object updateCarouse(ShopCarouse shopCarouse){
        return carouseService.updateCarouse(shopCarouse);
    }

    /**
     * 分页获取列表
     * @param pageNow
     * @param rows
     * @param condition
     * @param isDeleted
     * @return
     */
    @GetMapping("getList")
    public Object getList(Integer pageNow, Integer rows,String condition,String isDeleted){
        return carouseService.getList(pageNow,rows,condition,isDeleted);
    }

    /**
     * 上下架
     * @param id
     * @param isDeleted
     * @return
     */
    @PutMapping("upDown")
    public Object upDown(int id,String isDeleted){
        return carouseService.upDown(id,isDeleted);
    }
}
